package com.ynny.service;

import com.ynny.dao.BookDao;
import com.ynny.dao.BookDaoImpl;
import com.ynny.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    BookDao bookDao;

    @Autowired
    UserDao userDao;

    @Transactional
    @Override
    public void buyBook(Integer userId, Integer bookId) {
        //买书的业务逻辑
        //1.查询图书价格
        Integer price = bookDao.selectBookPriceById(bookId);
        //2.更新图书的库存
        bookDao.updateBookStockById(bookId);
        //3.更新用户的余额
        userDao.updateUserBalance(userId, price);


    }
}
